﻿
#include "wind_view.h"

///////////////////////////////////////////////////////////////////
WindowView::WindowView() {
    mTimeView    = nullptr;
    mUnTouchNext = [this](View &v, MotionEvent &et) { return true; };
}

WindowView::~WindowView() {
    WindowTime::ins()->delView(mTimeView);
}

void WindowView::setTimer(View *v) {
    mTimeView = __dc(TextView, v);
    if (!mTimeView) {
        LOG(ERROR) << "time view is null";
        return;
    }
    WindowTime::ins()->addView(mTimeView);
}

void WindowView::setTimer(int id) {
    setTimer(__get(id));
}

void WindowView::setBack(View *v) {
    if (!v) {
        LOG(ERROR) << "back view is null";
        return;
    }

    v->setOnClickListener(std::bind(&WindowView::backReturn, this, std::placeholders::_1));
}

void WindowView::setBack(int id) {
    setBack(__get(id));
}

void WindowView::backReturn(View &v) {
    closeView();
}

void WindowView::closeView() {
    closeWindow(this);
}

void WindowView::exitView() {
    // do something

    closeView();
}

void WindowView::onCreate() {
    // 加载窗口视图
    if (mVP == nullptr) {
        std::string xml = inflateXml();
        beforeInflate();
        if (!xml.empty()) {
            inflate(xml);
        }
        afterInflate();
    }
}

const std::string WindowView::inflateXml() const {
    return "";
}

void WindowView::beforeInflate(){
}

void WindowView::afterInflate(){
}
